package com.twu.biblioteca.command;

import com.twu.biblioteca.BibliotecaApp;
import com.twu.biblioteca.User;

/**
 * Created by jjwang on 4/23/14.
 */
public class Login implements Command {
    @Override
    public String doExecute(BibliotecaApp app) {
        System.out.println("username:");
        String username = app.input();
        System.out.println("password:");
        String password = app.input();
        for(User user:app.getUsers()){
            if(user.getUsername().equals(username)&&user.getPassword().equals(password)){
                app.setCurrentUser(user);
                app.getMenu().put("l",new Logout());
                app.getMenu().put("p",new Profile());
                return user.getUsername()+" Welcome back!\n";
            }
        }
        return "Sorry, Invalid Credential..\n";
    }

    @Override
    public String getName() {
        return "Login";
    }
}
